package appConfig

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/appconfig"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppConfigInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 详情
func NewAppConfigInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppConfigInfoLogic {
	return &AppConfigInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AppConfigInfoLogic) AppConfigInfo() (resp *types.AppConfigInfoData, err error) {
	u, err := l.svcCtx.SettingService.AppConfig.AppConfigInfo(l.ctx, &appconfig.AppConfigInfoReq{
		MerchantId: 1,
	})

	if err != nil {
		logc.Error(l.ctx, "AppConfigInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.AppConfigInfoData{
		RightOpen:             int64(u.Data.RightOpen),
		IconOpen:              int64(u.Data.IconOpen),
		IosDownUrl:            u.Data.IosDownUrl,
		IosVersion:            u.Data.IosVersion,
		IosHousingVersion:     u.Data.IosHousingVersion,
		AndroidDownUrl:        u.Data.AndroidDownUrl,
		AndroidVersion:        u.Data.AndroidVersion,
		AndroidHousingVersion: u.Data.AndroidHousingVersion,
		IsForceUpdate:         int64(u.Data.IsForceUpdate),
	}

	return resp, nil
}
